<?php 
namespace Home\Controller;
class AppraiseController extends HomeController {
    public function index(){
        $gid = I("get.gid");
        $model = M("goods");
        $data = $model->where('g_id="'.$gid.'"')->select();
        $this->assign('data',$data[0]);
        $this->display();
    }

    public function add(){
        $appraise = M("appraise");
        $email = $_SESSION['email'];
        $uid = M('user')->where('email="'.$email.'"')->select();
        $data['app_u_id'] = $uid[0]['u_id'];
        $data['app_time'] = time();
        $data['app_g_id'] = $_POST['gid'];
        $data['app_content'] = $_POST['content'];
        $data['app_star'] = $_POST['gstar'];
        $appraise->add($data);
        $status = M()->table('dota2_orders')->join('dota2_o_detail')->where('o_uid ="'.$uid[0]['u_id'].'" and o_rand_id = o_d_oid and o_d_gid = "'.$_POST['gid'].'"')->select();
        $id = $status[0]['o_d_id']; 
        $edit['o_d_status'] = 1;
        M('o_detail')->where('o_d_id="'.$id.'"')->save($edit);
        $this->success('新增成功', '/Home/Store/detail?gid='.$_POST['gid']);
    }

    public function status(){
        $gid = $_POST['gid'];
        $email = $_SESSION['email'];
        $uid = M('user')->where('email="'.$email.'"')->select();
        $uid = $uid[0]['u_id'];
        $list = M()->table('dota2_orders')->join('dota2_o_detail')->where('o_uid ="'.$uid.'" and o_rand_id = o_d_oid and o_d_gid = "'.$gid.'" and o_d_status = 0')->select();
        echo json_encode($list);
    }
}